<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Join Platform</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

</head>

<body class="bg-gradient-primary">

    <div class="container">

        <div class="card o-hidden border-0 shadow-lg my-5">
            <div class="card-body p-0">
                <!-- Nested Row within Card Body -->
                <div class="row"><img src="img/幽灵.gif" width="385" height="385" alt=""/>
<div class="col-lg-7">
            <div class="p-5">

                            <div class="text-center">
                                <h1 class="h4 text-gray-900 mb-4">Join an Existing Platform</h1>
                            </div>

                            <div class="form-group row"> 
                                    <div class="col-sm-12">                                      
                                        <select class="form-control " name="oname" id="oname" onchange="get_oname(this.value)">
                                            <option value ="volvo" hidden>--choose platform--</option>                                           
                                        </select>
                                    </div>
                            </div>

                            <div class="form-group row">
                                <div class="col-sm-12" >	
                                    <select class="form-control" name="user_authority" id="user_authority" >
                                        <option value ="volvo" hidden>--choose rolename--</option>
                                        <!-- <option value="-1">--choose rolename--</option> -->
                                    </select>                                    
                                </div>
                                <!-- <div class="col-sm-4 tips"></div> -->
                            </div>

                            <br>
                            <button type="button" class="btn btn-success btn-block" id="submit" >Submit</button>
                            <hr>

                            <div class="text-center">
                                <a class="small" href="login.html">Return to the Login Page</a>
                            </div>

                            <br>
                            <br>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>


    <script type="text/javascript">
        var url=decodeURI(location.href);
        var num=url.indexOf("?");
        var str=url.substr(num+1);
        //console.log(str);

    </script>


<script>
     $(document).ready(function(){
        var value=$(this).val;
        $.ajax({
        timeout: 3000,
        type: "get",
        url: "http://210.30.97.103:20305/admin/AllApplicablePlatforms",
        dataType: 'json',
        //data: {},
        success: function (data) {
            console.log(data);
            //var Opt="<option value='' hidden selected='selected'>--choose platform--</option>";    
            // for (i in data)
            // {
            //   Opt+="<option>"+data[i].oname+"</option>";           
            // }
            // $('#oname').html(Opt);
            $.each(data, function (i) {
                console.log(data[i]);
                var trString = " <option>" + data[i].oname + "</option>";
                $("#oname").append(trString);
            });
        }
        });
    });  

    function get_oname(obj){
        console.log(obj);
        var oname=obj;
        $.ajax({
            typr:"get",
            dataType:"json",
            url:"http://210.30.97.103:20305/register/state",
            data:{
                "oname":oname
            },
            success:function(data) {
                //var jsonList=eval("("+data+")");
                //var len = jsonList.length;
                //alert(jsonList);

                console.log(data);

                //document.getElementById("user_authority").innerHTML = "";
                $("#user_authority").empty();
                $("#user_authority").append("<option value =\"volvo\" hidden>--choose rolename--</option>");
                for (var i = 0; i < data.length; i++) {
                  //  $("#user_authority").append("<option>" + data[i].user_authority + "</option>");
                    for (var i = 0; i < data.length; i++) {
                        $("#user_authority").append("<option>" + data[i].authority + "</option>");
                    }
                }
            }});
    }

    $("#submit").click(function(){
        var user_authority=$("#user_authority").val();
        var oname=$("#oname").val();
        if($("#user_authority").val()=="volvo"||$("#oname").val()=="volvo"){
            alert("请选择！");
        }
        else{

            $.ajax({
            type:"put",
            url:"http://210.30.97.103:20305/register/selectedplatform",
            data:{
                "oname":oname,
                "username":str,
                "authority":user_authority
            },
            success:function(data){
                console.log(data);
                if(data==1){
                    alert("提交成功！请等待审核！");
                }
                else{
                    alert("提交失败！")
                }
            }
        });
        }
        
        
    });
    // $("#submit").click(get_user_authority);
    // function get_user_authority(obj){
    //     console.log(obj);
    //     var user_authority=obj;
    //     $.ajax({
    //         typr:"get",
    //         dataType:"json",
    //         url:"http://rap2api.tao bao.org/app/mock/281919/user_authority",
    //         data:{
    //             "user_authority":user_authority
    //         },
    //         success:function(data){
    //             console.log(data);
    //         },
    //     })
    // }
</script> 




</body>

</html>